home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 1998 November / IRIX 6.5.2 Base Documentation November 1998.img / usr / share / catman / p_man / cat3 / tserialio.z / tserialio
Text File  |  1998-10-20  |  45KB  |  727 lines

  1.  
  2.  
  3.  
  4. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      tserialio, libtserialio, tsintro, tsClosePort, tsCopyConfig,
  10.      tsFreeConfig, tsGetErrorHandler, tsGetFD, tsGetFillPoint,
  11.      tsGetFillPointBytes, tsGetFilledBytes, tsNewConfig, tsNewConfigFromPort,
  12.      tsOpenPort, tsRead, tsSetCflag, tsSetDirection, tsSetErrorHandler,
  13.      tsSetExternalClockFactor, tsSetFillPointBytes, tsSetOspeed,
  14.      tsSetPortName, tsSetProtocol, tsSetQueueSize, tsWrite - timestamped
  15.      serial port i/o
  16.  
  17. CCCC SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  18.      ####iiiinnnncccclllluuuuddddeeee <<<<ttttsssseeeerrrriiiiaaaalllliiiioooo....hhhh>>>>
  19.  
  20.      Link with -ltserialio
  21.  
  22.      Choosing a Port Configuration:
  23.  
  24.      TTTTSSSSccccoooonnnnffffiiiigggg ttttssssNNNNeeeewwwwCCCCoooonnnnffffiiiigggg((((vvvvooooiiiidddd))));;;;
  25.      TTTTSSSSccccoooonnnnffffiiiigggg ttttssssNNNNeeeewwwwCCCCoooonnnnffffiiiiggggFFFFrrrroooommmmPPPPoooorrrrtttt((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  26.      TTTTSSSSccccoooonnnnffffiiiigggg ttttssssCCCCooooppppyyyyCCCCoooonnnnffffiiiigggg((((TTTTSSSSccccoooonnnnffffiiiigggg ffffrrrroooommmm))));;;;
  27.      TTTTSSSSssssttttaaaattttuuuussss ttttssssFFFFrrrreeeeeeeeCCCCoooonnnnffffiiiigggg((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg))));;;;
  28.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttPPPPoooorrrrttttNNNNaaaammmmeeee((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, cccchhhhaaaarrrr ****nnnnaaaammmmeeee))));;;;
  29.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttDDDDiiiirrrreeeeccccttttiiiioooonnnn((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, iiiinnnntttt ddddiiiirrrreeeeccccttttiiiioooonnnn))));;;;
  30.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttQQQQuuuueeeeuuuueeeeSSSSiiiizzzzeeee((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, iiiinnnntttt qqqquuuueeeeuuuueeeessssiiiizzzzeeee))));;;;
  31.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttCCCCffffllllaaaagggg((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, ttttccccffffllllaaaagggg____tttt ccccffffllllaaaagggg))));;;;
  32.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttOOOOssssppppeeeeeeeedddd((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, ssssppppeeeeeeeedddd____tttt oooossssppppeeeeeeeedddd))));;;;
  33.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttPPPPrrrroooottttooooccccoooollll((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, iiiinnnntttt pppprrrroooottttooooccccoooollll))));;;;
  34.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttEEEExxxxtttteeeerrrrnnnnaaaallllCCCClllloooocccckkkkFFFFaaaaccccttttoooorrrr((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,,
  35.                                        iiiinnnntttt eeeexxxxttttcccclllloooocccckkkk____ffffaaaaccccttttoooorrrr))));;;;
  36.  
  37.      Opening and Using a Port:
  38.  
  39.      TTTTSSSSssssttttaaaattttuuuussss ttttssssOOOOppppeeeennnnPPPPoooorrrrtttt((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, TTTTSSSSppppoooorrrrtttt ****rrrreeeettttuuuurrrrnnnnPPPPoooorrrrtttt))));;;;
  40.      TTTTSSSSssssttttaaaattttuuuussss ttttssssCCCClllloooosssseeeePPPPoooorrrrtttt((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  41.      iiiinnnntttt ttttssssGGGGeeeettttFFFFiiiilllllllleeeeddddBBBByyyytttteeeessss((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  42.      TTTTSSSSssssttttaaaattttuuuussss ttttssssRRRReeeeaaaadddd((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt,,,, uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr ****ddddaaaattttaaaa,,,, ssssttttaaaammmmpppp____tttt ****ssssttttaaaammmmppppssss,,,,
  43.                      iiiinnnntttt nnnnbbbbyyyytttteeeessss))));;;;
  44.      TTTTSSSSssssttttaaaattttuuuussss ttttssssWWWWrrrriiiitttteeee((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt,,,, uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr ****ddddaaaattttaaaa,,,, ssssttttaaaammmmpppp____tttt ****ssssttttaaaammmmppppssss,,,,
  45.                       iiiinnnntttt nnnnbbbbyyyytttteeeessss))));;;;
  46.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt,,,, iiiinnnntttt nnnnbbbbyyyytttteeeessss))));;;;
  47.      iiiinnnntttt ttttssssGGGGeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  48.      iiiinnnntttt ttttssssGGGGeeeettttFFFFDDDD((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  49.  
  50.      Error Handling:
  51.  
  52.      TTTTSSSSeeeerrrrrrrrffffuuuunnnncccc ttttssssSSSSeeeettttEEEErrrrrrrroooorrrrHHHHaaaannnnddddlllleeeerrrr((((TTTTSSSSeeeerrrrrrrrffffuuuunnnncccc nnnneeeewwwwffffuuuunnnncccc,,,, iiiinnnntttt iiiinnnncccclllluuuuddddeeeeffffuuuunnnnccccnnnnaaaammmmeeee))));;;;
  53.      TTTTSSSSeeeerrrrrrrrffffuuuunnnncccc ttttssssGGGGeeeettttEEEErrrrrrrroooorrrrHHHHaaaannnnddddlllleeeerrrr((((iiiinnnntttt ****iiiinnnncccclllluuuuddddeeeeffffuuuunnnnccccnnnnaaaammmmeeee))));;;;
  54.  
  55. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  56.      The tserialio library provides millisecond accurate, timestamped access
  57.      to a serial port.  An application can measure the time at which each
  58.      input byte arrived at a serial port to within plus or minus one
  59.      millisecond.  An application can also schedule bytes to go out a serial
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  71.  
  72.  
  73.  
  74.      port at a specified time in the future.  The operating system will output
  75.      each byte at the specified time with an accuracy of plus or minus one
  76.      millisecond.  Times are specified on the UST timeline, the same timeline
  77.      used for other devices such as audio and video (see ddddmmmmGGGGeeeettttUUUUSSSSTTTT(3dm)).  See
  78.      ACCURACY AND LATENCY below for more information about the accuracy and
  79.      latency guarantees which tserialio offers.
  80.  
  81.      Tserialio is useful for timely serial port tasks such as machine control,
  82.      video deck control, or motion capture.  It is also useful for MIDI,
  83.      though the MIDI library (see mmmmddddIIIInnnnttttrrrroooo(3dm)) may be more appropriate in
  84.      this case.
  85.  
  86.      Tserialio is currently only supported on O2 workstations.
  87.  
  88.  
  89. OOOOVVVVEEEERRRRVVVVIIIIEEEEWWWW
  90.      A TSport represents one serial port open in one direction.  In order to
  91.      open a TSport, you specify how you would like the port configured using a
  92.      TSconfig.  This code shows you how to create a TSconfig and set its
  93.      various members:
  94.  
  95.           {
  96.             TSconfig config = tsNewConfig();
  97.             TSport port;
  98.  
  99.             tsSetPortName(config, "/dev/ttyts1");          /* required */
  100.             tsSetDirection(config, TS_DIRECTION_TRANSMIT); /* required */
  101.             tsSetQueueSize(config, 200);                   /* required */
  102.             tsSetCflag(config, CS8|PARENB|PARODD);         /* required */
  103.             tsSetOspeed(config, 38400);                    /* required */
  104.             tsSetProtocol(config, TS_PROTOCOL_RS232);      /* optional */
  105.             tsSetExternalClockFactor(config, 0);           /* optional */
  106.  
  107.             if (TS_SUCCESS != tsOpenPort(config, &port))
  108.               exit(2);
  109.  
  110.             tsFreeConfig(config);
  111.  
  112.             ... use the port ...
  113.  
  114.             tsClosePort(port);
  115.           }
  116.  
  117.  
  118.      The C types TSport and TSconfig are opaque pointers which you should
  119.      simply pass into the tserialio calls and never dereference.  The format
  120.      of the data to which they point is not exported.
  121.  
  122.      If you opened a TS_DIRECTION_TRANSMIT port, then use code like this to
  123.      actually schedule bytes for output:
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  137.  
  138.  
  139.  
  140.           {
  141.             stamp_t stamps[NBYTES];
  142.             unsigned char data[NBYTES];
  143.             int i;
  144.             for(i=0; i < NBYTES; i++) {
  145.               data[i] = a byte of data;
  146.               stamps[i] = UST time to transmit that byte;
  147.             }
  148.             tsWrite(port, &data, &stamps, NBYTES);
  149.           }
  150.  
  151.  
  152.      If you opened a TS_DIRECTION_RECEIVE port, then use code like this to
  153.      acquire input bytes and their arrival times:
  154.  
  155.  
  156.           {
  157.             stamp_t stamps[NBYTES];
  158.             unsigned char data[NBYTES];
  159.             tsRead(port, &data, &stamps, NBYTES);
  160.             int i;
  161.             for(i=0; i < NBYTES; i++) {
  162.               data[i] contains a byte of data;
  163.               stamps[i] contains UST time at which byte arrived;
  164.             }
  165.           }
  166.  
  167.  
  168.      A TSport has a queue of (byte,timestamp) pairs whose capacity you specify
  169.      with ttttssssSSSSeeeettttQQQQuuuueeeeuuuueeeeSSSSiiiizzzzeeee(3).
  170.  
  171.      For an input port (TS_DIRECTION_RECEIVE), this queue holds the bytes
  172.      which have been received but which you have not yet read using ttttssssRRRReeeeaaaadddd(3).
  173.      Characters that arrive on a port whose queue is full will be discarded.
  174.      If you attempt to read more characters than are currently available on
  175.      the queue, then ttttssssRRRReeeeaaaadddd(3) will block until your request can be satisfied.
  176.  
  177.      For an output port (TS_DIRECTION_TRANSMIT), this queue holds the bytes
  178.      which you have enqueued using ttttssssWWWWrrrriiiitttteeee(3) but which have not yet been
  179.      transmitted.  If you attempt to enqueue so much data that this queue
  180.      would fill past its capacity, then ttttssssWWWWrrrriiiitttteeee(3) will block until enough
  181.      space has become available to enqueue all of your data.
  182.  
  183.      You can determine the number of (byte,timestamp) pairs currently enqueued
  184.      on a TSport using ttttssssGGGGeeeettttFFFFiiiilllllllleeeeddddBBBByyyytttteeeessss(3).  You can also use
  185.      ttttssssSSSSeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss(3) and ttttssssGGGGeeeettttFFFFDDDD(3) to get a file descriptor for use in
  186.      sssseeeelllleeeecccctttt(2) or ppppoooollllllll(2) which will unblock when a specified amount of data
  187.      or space has become available in a TSport.
  188.  
  189.      TS functions which can err return a TSstatus.  A return value of
  190.      TS_SUCCESS means that the function was successful, otherwise a TS_ERROR_
  191.      token is returned to describe the error.  See ERROR HANDLING below for
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  203.  
  204.  
  205.  
  206.      more information.
  207.  
  208.  
  209. CCCCOOOONNNNFFFFIIIIGGGGUUUURRRRIIIINNNNGGGG AAAA PPPPOOOORRRRTTTT
  210.      TTTTSSSSccccoooonnnnffffiiiigggg ttttssssNNNNeeeewwwwCCCCoooonnnnffffiiiigggg((((vvvvooooiiiidddd))));;;;
  211.  
  212.      Create a new TSconfig.  Can fail with NULL
  213.      (oserror()==TS_ERROR_OUT_OF_MEM).
  214.  
  215.      TTTTSSSSccccoooonnnnffffiiiigggg ttttssssNNNNeeeewwwwCCCCoooonnnnffffiiiiggggFFFFrrrroooommmmPPPPoooorrrrtttt((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  216.  
  217.      Create a new TSconfig with the same configuration as _p_o_r_t.  Can fail with
  218.      NULL (oserror()==TS_ERROR_OUT_OF_MEM).
  219.  
  220.      TTTTSSSSccccoooonnnnffffiiiigggg ttttssssCCCCooooppppyyyyCCCCoooonnnnffffiiiigggg((((TTTTSSSSccccoooonnnnffffiiiigggg ffffrrrroooommmm))));;;;
  221.  
  222.      Create a new TSconfig in exactly the same state as _f_r_o_m.  _F_r_o_m is not
  223.      modified.  Can fail with NULL (oserror()==TS_ERROR_OUT_OF_MEM).
  224.  
  225.      TTTTSSSSssssttttaaaattttuuuussss ttttssssFFFFrrrreeeeeeeeCCCCoooonnnnffffiiiigggg((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg))));;;;
  226.  
  227.      Free a TSconfig.
  228.  
  229.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttPPPPoooorrrrttttNNNNaaaammmmeeee((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, cccchhhhaaaarrrr ****nnnnaaaammmmeeee))));;;;
  230.  
  231.      Set UNIX filename of timestamped serial port to open.  This should be a
  232.      UNIX device node of the form ////ddddeeeevvvv////ttttttttyyyyttttssssn.  ////ddddeeeevvvv////ttttttttyyyyttttssssn represents the
  233.      same physical port as the traditional device node ////ddddeeeevvvv////ttttttttyyyyddddn as described
  234.      in sssseeeerrrriiiiaaaallll(7).  This call can fail with TS_ERROR_OUT_OF_MEM.
  235.  
  236.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttDDDDiiiirrrreeeeccccttttiiiioooonnnn((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, iiiinnnntttt ddddiiiirrrreeeeccccttttiiiioooonnnn))));;;;
  237.  
  238.      Specify direction of timestamped serial port:
  239.  
  240.      o TS_DIRECTION_TRANSMIT for an "output" port to which you can ttttssssWWWWrrrriiiitttteeee(3).
  241.  
  242.      o TS_DIRECTION_RECEIVE  for in "input" port from which you can ttttssssRRRReeeeaaaadddd(3).
  243.  
  244.      o call fails with TS_ERROR_BAD_LIBRARY_CALL for any other _d_i_r_e_c_t_i_o_n
  245.  
  246.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttQQQQuuuueeeeuuuueeeeSSSSiiiizzzzeeee((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, iiiinnnntttt qqqquuuueeeeuuuueeeessssiiiizzzzeeee))));;;;
  247.  
  248.      Specify the number of (byte,timestamp) pairs which the port's queue can
  249.      hold.  Fails with TS_ERROR_BAD_LIBRARY_CALL if specified size is 0 or
  250.      less.  Currently, the queue size must be greater than or equal to 20, and
  251.      less than 102400.  See OVERVIEW above for information about this queue.
  252.  
  253.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttCCCCffffllllaaaagggg((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, ttttccccffffllllaaaagggg____tttt ccccffffllllaaaagggg))));;;;
  254.  
  255.      Specify most serial communication parameters, using the traditional
  256.      struct termios.c_cflag flags (see tttteeeerrrrmmmmiiiioooossss(7)):
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  269.  
  270.  
  271.  
  272.          CSIZE bits (CS5, CS6, CS7, CS8)
  273.          CSTOPB bit (1==2 stop bits, 0==1 stop bits)
  274.          PARENB (0==no parity, 1==see PARODD)
  275.          PARODD (1==odd parity, 0==even parity)
  276.          CBAUD (B9600 etc.) is IGNORED
  277.                this field of c_cflag has been obsoleted.
  278.                use tsSetOspeed(3) instead.
  279.  
  280.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttOOOOssssppppeeeeeeeedddd((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, ssssppppeeeeeeeedddd____tttt oooossssppppeeeeeeeedddd))));;;;
  281.  
  282.      Specify baud rate as integer in symbols per second (e.g. 9600, 31250
  283.      (MIDI), 38400 (video deck control)).  Fails with
  284.      TS_ERROR_BAD_LIBRARY_CALL if _s_p_e_e_d is 0.
  285.  
  286.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttPPPPrrrroooottttooooccccoooollll((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, iiiinnnntttt pppprrrroooottttooooccccoooollll))));;;;
  287.  
  288.      Specify electrical protocol to use on serial port:
  289.  
  290.      o TS_PROTOCOL_RS232 (the default): EIA/TIA-232-E
  291.  
  292.      o TS_PROTOCOL_RS422: EIA/TIA-422-B
  293.  
  294.      o TS_PROTOCOL_MACINTOSH: Macintosh compatible serial levels
  295.  
  296.      o fails with TS_ERROR_BAD_LIBRARY_CALL for other _p_r_o_t_o_c_o_l.
  297.  
  298.      See sssseeeerrrriiiiaaaallll(7) for information about which protocols are supported on
  299.      which platforms.
  300.  
  301.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttEEEExxxxtttteeeerrrrnnnnaaaallllCCCClllloooocccckkkkFFFFaaaaccccttttoooorrrr((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,,
  302.                                        iiiinnnntttt eeeexxxxttttcccclllloooocccckkkk____ffffaaaaccccttttoooorrrr))));;;;
  303.  
  304.      Specify clock source for serial port:
  305.  
  306.      o 0 (the default) means the serial port should use its internal clock.
  307.  
  308.      o N (N > 1) means the serial port should clock itself off of the provided
  309.      external clock divided by N. ttttssssSSSSeeeettttOOOOSSSSppppeeeeeeeedddd(3) is ignored in this case.
  310.  
  311.      o N < 0 fails with TS_ERROR_BAD_LIBRARY_CALL.
  312.  
  313.      To use a Macintosh-compatible MIDI dongle plugged into a serial port of
  314.      an Indigo, Indy, and Indigo2, specify 32.  The MIDI dongle provides a 1
  315.      MHz external clock signal on a pin of the serial port, which drives the
  316.      serial port at the MIDI (1,000,000/32==31.25kHz) baud rate.  On the O2
  317.      system, use the internal clock and set ospeed to 31250.
  318.  
  319.  
  320. OOOOPPPPEEEENNNNIIIINNNNGGGG AAAANNNNDDDD UUUUSSSSIIIINNNNGGGG AAAA PPPPOOOORRRRTTTT
  321.      TTTTSSSSssssttttaaaattttuuuussss ttttssssOOOOppppeeeennnnPPPPoooorrrrtttt((((TTTTSSSSccccoooonnnnffffiiiigggg ccccoooonnnnffffiiiigggg,,,, TTTTSSSSppppoooorrrrtttt ****rrrreeeettttuuuurrrrnnnnPPPPoooorrrrtttt))));;;;
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  335.  
  336.  
  337.  
  338.      Open a timestamped serial port.  Each TSport represents a connection to
  339.      one physical serial port in one direction.  Each TS_DIRECTION_RECEIVE
  340.      TSport will receive its own copy of the data arriving at the physical
  341.      serial port.  On TS_PROTOCOL_RS232 serial ports, DTR and RTS are always
  342.      asserted, and DCD and CTS are ignored.  Hanging up the serial line (see
  343.      tttteeeerrrrmmmmiiiioooossss(3)) is not currently supported.
  344.  
  345.      ttttssssOOOOppppeeeennnnPPPPoooorrrrtttt(3) can fail in the following cases:
  346.  
  347.      o TS_ERROR_BAD_LIBRARY_CALL if _c_o_n_f_i_g or _r_e_t_u_r_n_P_o_r_t are NULL or invalid.
  348.  
  349.      o TS_ERROR_BAD_LIBRARY_CALL if you had not set the following parameters
  350.      of _c_o_n_f_i_g:  ttttssssSSSSeeeettttPPPPoooorrrrttttNNNNaaaammmmeeee(3), ttttssssSSSSeeeettttDDDDiiiirrrreeeeccccttttiiiioooonnnn(3), ttttssssSSSSeeeettttQQQQuuuueeeeuuuueeeeSSSSiiiizzzzeeee(3),
  351.      ttttssssSSSSeeeettttCCCCffffllllaaaagggg(3), or ttttssssSSSSeeeettttOOOOssssppppeeeeeeeedddd(3).
  352.  
  353.      o TS_ERROR_OPENING_PORT if a parameter specified in _c_o_n_f_i_g is not
  354.      supported on the specified serial port, or there is some problem
  355.      interfacing with the tserialio driver.
  356.  
  357.      o TS_ERROR_OPENING_PORT if _c_o_n_f_i_g specifies an invalid queuesize (see
  358.      ttttssssSSSSeeeettttQQQQuuuueeeeuuuueeeeSSSSiiiizzzzeeee(3)).
  359.  
  360.      o TS_ERROR_OPENING_PORT if opening the port would exceed tserialio's
  361.      fixed per-system limit on the number of simultaneously open TSports.
  362.      This limit is at least eight times the number of physical serial ports on
  363.      the machine.
  364.  
  365.      o TS_ERROR_PORT_BUSY if _c_o_n_f_i_g specifies TS_DIRECTION_TRANSMIT on a port
  366.      which is already open for transmit using tserialio.
  367.  
  368.      o TS_ERROR_PORT_BUSY if _c_o_n_f_i_g specifies a physical port which is already
  369.      open using tserialio with different communications parameters (cflag,
  370.      ospeed, protocol, or extclock).
  371.  
  372.      o TS_ERROR_PORT_BUSY if _c_o_n_f_i_g specifies a port which is already open
  373.      using the traditional serial interface (see sssseeeerrrriiiiaaaallll(7)).
  374.  
  375.      o TS_ERROR_OUT_OF_MEM.
  376.  
  377.      TTTTSSSSssssttttaaaattttuuuussss ttttssssCCCClllloooosssseeeePPPPoooorrrrtttt((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  378.  
  379.      Close a TSport.  If the port is a TS_DIRECTION_TRANSMIT port, all
  380.      currently enqueued (byte,timestamp) pairs will be discarded immediately
  381.      and not transmitted.
  382.  
  383.      iiiinnnntttt ttttssssGGGGeeeettttFFFFiiiilllllllleeeeddddBBBByyyytttteeeessss((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  384.  
  385.      Returns the total number of (byte,timestamp) pairs currently in the
  386.      TSport's queue.
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  401.  
  402.  
  403.  
  404.      TTTTSSSSssssttttaaaattttuuuussss ttttssssRRRReeeeaaaadddd((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt,,,, uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr ****ddddaaaattttaaaa,,,, ssssttttaaaammmmpppp____tttt ****ssssttttaaaammmmppppssss,,,,
  405.                      iiiinnnntttt nnnnbbbbyyyytttteeeessss))));;;;
  406.  
  407.      Reads nbytes (byte,timestamp) pairs from the specified port's queue.  The
  408.      port must be a TS_DIRECTION_RECEIVE port (see ttttssssSSSSeeeettttDDDDiiiirrrreeeeccccttttiiiioooonnnn(3)).  The
  409.      function returns the data of each byte in data[i], and the UST time at
  410.      which the byte came in the input jack of the machine in stamps[i].  The
  411.      actual reception time of data[i] is guaranteed to be within the interval
  412.      from (stamps[i] - 2 milliseconds) to (stamps[i]).  If nbytes
  413.      (byte,timestamp) pairs are not currently available in the port's queue,
  414.      then ttttssssRRRReeeeaaaadddd(3) will block until it has been able to read all nbytes
  415.      pairs.
  416.  
  417.      If ttttssssRRRReeeeaaaadddd(3) needs to block, it will call sssseeeelllleeeecccctttt(2).  If that select
  418.      fails for any reason other than EINTR, the call will return with
  419.      TS_ERROR_SELECT_FAILED.
  420.  
  421.      Currently, tserialio does not provide an indication of framing, parity,
  422.      or overrun errors.
  423.  
  424.  
  425.      TTTTSSSSssssttttaaaattttuuuussss ttttssssWWWWrrrriiiitttteeee((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt,,,, uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr ****ddddaaaattttaaaa,,,, ssssttttaaaammmmpppp____tttt ****ssssttttaaaammmmppppssss,,,,
  426.                       iiiinnnntttt nnnnbbbbyyyytttteeeessss))));;;;
  427.  
  428.      Writes (enqueues) nbytes (byte,timestamp) pairs to the specified port's
  429.      queue.  The port must be a TS_DIRECTION_TRANSMIT port (see
  430.      ttttssssSSSSeeeettttDDDDiiiirrrreeeeccccttttiiiioooonnnn(3)).  This call schedules each byte data[i] to go out at
  431.      the UST time given by stamps[i].  The actual transmission time of data[i]
  432.      is guaranteed to be within the interval from (stamps[i]) to (stamps[i] +
  433.      2 milliseconds).  If sufficient space is not available in the port's
  434.      queue to write all nbytes (byte,timestamp) pairs immediately, then
  435.      ttttssssWWWWrrrriiiitttteeee(3) will block until it has been able to write all nbytes pairs.
  436.  
  437.      If ttttssssWWWWrrrriiiitttteeee(3) needs to block, it will call sssseeeelllleeeecccctttt(2).  If that select
  438.      fails for any reason other than EINTR, the call will return with
  439.      TS_ERROR_SELECT_FAILED.
  440.  
  441.      The timestamps you provide to ttttssssWWWWrrrriiiitttteeee(3) must be non-decreasing.
  442.      Tserialio will transmit every byte you enqueue exactly once; it will
  443.      transmit a byte late rather than dropping it.  Be careful that the
  444.      (byte,timestamp) pairs you enqueue on the serial port are (at least in
  445.      the long term) realizable given the baud rate and communications
  446.      parameters you have chosen, otherwise you will lose the accuracy
  447.      guarantee described above, and possibly also overflow your queue.
  448.  
  449.      iiiinnnntttt ttttssssGGGGeeeettttFFFFDDDD((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  450.      TTTTSSSSssssttttaaaattttuuuussss ttttssssSSSSeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt,,,, iiiinnnntttt nnnnbbbbyyyytttteeeessss))));;;;
  451.      iiiinnnntttt ttttssssGGGGeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss((((TTTTSSSSppppoooorrrrtttt ppppoooorrrrtttt))));;;;
  452.  
  453.      ttttssssGGGGeeeettttFFFFDDDD(3) returns a file descriptor which you can pass to sssseeeelllleeeecccctttt(2) or
  454.      ppppoooollllllll(2) if you want to block until data becomes available in an input
  455.      port, or space becomes available in an output port.
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  467.  
  468.  
  469.  
  470.      Before calling sssseeeelllleeeecccctttt(2) or ppppoooollllllll(2), you must first call
  471.      ttttssssSSSSeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss(3) to specify when you want to unblock:
  472.  
  473.      INPUT PORTS:  will unblock from select() or poll() when
  474.                    tsGetFilledBytes() >= tsGetFillPointBytes()
  475.  
  476.      OUTPUT PORTS: will unblock from select() or poll() when
  477.                    tsGetFilledBytes() <  tsGetFillPointBytes()
  478.  
  479.      The calls ttttssssWWWWrrrriiiitttteeee(3) and ttttssssRRRReeeeaaaadddd(3) may change the fillpoint, so you
  480.      should make sure to call ttttssssSSSSeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss(3) before each invocation of
  481.      sssseeeelllleeeecccctttt(2) or ppppoooollllllll(2).
  482.  
  483.      When using sssseeeelllleeeecccctttt(2), an input port's file descriptor is used in a read
  484.      fdset and an output port's file descriptor is used in a write fdset.
  485.  
  486.      When using ppppoooollllllll(2), an input port's file descriptor is used with the
  487.      POLLIN event flag and an output port's file descriptor is used with a
  488.      POLLOUT event flag.
  489.  
  490.      AL Note: the definition of output fillpoint differs from that in the SGI
  491.      Audio Library (see AAAALLLLiiiinnnnttttrrrroooo(3dm)).  The AL file descriptor unblocks when
  492.      there are more than "fillpoint" spaces in the queue.  This inconsistency
  493.      was necessary to facilitate a future feature of this library: the ability
  494.      to choose fillpoints in units of time rather than data.
  495.  
  496.      ttttssssSSSSeeeettttFFFFiiiillllllllPPPPooooiiiinnnnttttBBBByyyytttteeeessss(3) will fail with TS_ERROR_BAD_LIBRARY_CALL if _n_b_y_t_e_s
  497.      is less than zero or greater than the port's queue size.
  498.  
  499.  
  500. TTTTHHHHRRRREEEEAAAADDDD SSSSAAAAFFFFEEEETTTTYYYY
  501.      Applications can make multiple, simultaneous, uncoordinated TS calls on
  502.      different TSports from different threads and the library will operate
  503.      fine.  Each TSport completely encapsulates the state needed to do
  504.      operations on that TSport (except for error handling, which is explained
  505.      next).
  506.  
  507.      Applications cannot make multiple, simultaneous, uncoordinated TS calls
  508.      from different threads to set or access the library's global state--
  509.      namely, the error handler function described below.  If two threads
  510.      simultaneously try to set the global error handler (even the same error
  511.      handler), the behavior is undefined.  Furthermore, if the application
  512.      writes an error handler, then makes multiple, simultaneous, uncoordinated
  513.      TS calls on different TSports from different threads, and both TS calls
  514.      issue an error simultaneously, then two instances of the application's
  515.      error handler will be called in a simultaneous, uncoordinated manner in
  516.      two threads.  Applications may need semaphore protection in their error
  517.      handler if this is possible.  Each function in this man page documents
  518.      the possible error return values.
  519.  
  520.      Applications cannot make multiple, simultaneous, uncoordinated TS calls
  521.      on the same TSport from different threads, even if the order of execution
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  533.  
  534.  
  535.  
  536.      of those calls does not matter to the application.  Doing so will very
  537.      likely cause a core dump, or at least corruption of the TSport.  An
  538.      application which accesses a given TSport from multiple threads should
  539.      use a semaphore package such as POSIX semaphores (man sssseeeemmmm____iiiinnnniiiitttt(3C)).
  540.  
  541.  
  542. EEEERRRRRRRROOOORRRR HHHHAAAANNNNDDDDLLLLIIIINNNNGGGG
  543.      TTTTSSSSeeeerrrrrrrrffffuuuunnnncccc ttttssssSSSSeeeettttEEEErrrrrrrroooorrrrHHHHaaaannnnddddlllleeeerrrr((((TTTTSSSSeeeerrrrrrrrffffuuuunnnncccc nnnneeeewwwwffffuuuunnnncccc,,,, iiiinnnntttt iiiinnnncccclllluuuuddddeeeeffffuuuunnnnccccnnnnaaaammmmeeee))));;;;
  544.      TTTTSSSSeeeerrrrrrrrffffuuuunnnncccc ttttssssGGGGeeeettttEEEErrrrrrrroooorrrrHHHHaaaannnnddddlllleeeerrrr((((iiiinnnntttt ****iiiinnnncccclllluuuuddddeeeeffffuuuunnnnccccnnnnaaaammmmeeee____rrrreeeetttt))));;;;
  545.  
  546.      Functions that can err return a TSstatus.  TS_SUCCESS means success.  On
  547.      failure, functions return a TS_ERROR_ token as seen in <tserialio.h>, and
  548.      also set oooosssseeeerrrrrrrroooorrrr(3C) to the value of that token.
  549.  
  550.      Errors are also reported as they occur by the execution of a process-
  551.      global, non-thread-safe error handler callback which you can set.  The
  552.      string passed to the error handler contains detailed error information
  553.      which is useful for debugging.
  554.  
  555.      The default error handler prints an error to stderr.  When defining an
  556.      error handler, you can specify using _i_n_c_l_u_d_e_f_u_n_c_n_a_m_e whether or not to
  557.      include the TS function name that is erring in the string.  Most
  558.      applications will want to turn off the error handler in non-debug
  559.      compiles using something like this:
  560.  
  561.  
  562.           #ifdef NDEBUG
  563.              tsSetErrorHandler(NULL, FALSE);
  564.           #endif
  565.  
  566.  
  567.      ttttssssSSSSeeeettttEEEErrrrrrrroooorrrrHHHHaaaannnnddddlllleeeerrrr(3) sets a new error handler and returns the previous
  568.      handler.  ttttssssGGGGeeeettttEEEErrrrrrrroooorrrrHHHHaaaannnnddddlllleeeerrrr(3) returns the current error handler and
  569.      _i_n_c_l_u_d_e_f_u_n_c_n_a_m_e status.  _i_n_c_l_u_d_e_f_u_n_c_n_a_m_e__r_e_t can be NULL.
  570.  
  571.      Programmatic errors, where you pass an out-of-range, nonsensical, or
  572.      otherwise illegal value to an TS library call, all return
  573.      TS_ERROR_BAD_LIBRARY_CALL.
  574.  
  575.  
  576. PPPPEEEERRRRFFFFOOOORRRRMMMMAAAANNNNCCCCEEEE TTTTIIIIPPPPSSSS
  577.      Tserialio is built on a mechanism which is extremely lightweight compared
  578.      to the standard ////ddddeeeevvvv////ttttttttyyyyddddn serial interface.  The mechanism is similar to
  579.      the lightweight mapped ringbuffers offered by the Audio Serial Option
  580.      (see aaaassssoooosssseeeerrrrnnnnssss(7)).  These facts are true of the current implementation
  581.      and are likely (not guaranteed) to remain true:
  582.  
  583.      o ttttssssGGGGeeeettttFFFFiiiilllllllleeeeddddBBBByyyytttteeeessss(3) performs no system calls and is extremely
  584.      efficient.
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  599.  
  600.  
  601.  
  602.      o A ttttssssRRRReeeeaaaadddd(3) which can be satisfied by data currently in the port's
  603.      queue is little more than a bcopy and requires no system calls.
  604.  
  605.      o A ttttssssWWWWrrrriiiitttteeee(3) for which there is room in the port's queue is similarly
  606.      efficient.
  607.  
  608.      Therefore, an application which periodically polls ttttssssGGGGeeeettttFFFFiiiilllllllleeeeddddBBBByyyytttteeeessss(3)
  609.      can perform all of its serial i/o without any system calls.  This may be
  610.      desirable for applications in which a convenient periodic opportunity for
  611.      polling the serial device is available without spinning on the CPU.  For
  612.      example, this may be the case with a video deck control application.
  613.  
  614.  
  615.  
  616. AAAACCCCCCCCUUUURRRRAAAACCCCYYYY AAAANNNNDDDD LLLLAAAATTTTEEEENNNNCCCCYYYY
  617.      Tserialio offers guarantees about the accuracy of its input byte
  618.      timestamping and its output byte scheduling.  These guarantees are
  619.      described along with ttttssssWWWWrrrriiiitttteeee(3) and ttttssssRRRReeeeaaaadddd(3) above.
  620.  
  621.      Tserialio offers no guarantees about the latencies your application sees.
  622.      It has no interactions whatsoever with the IRIX scheduler.  It is a
  623.      service which pairs together bytes of data and UST times in such a way
  624.      that your application can manipulate the pair atomically.
  625.  
  626.      1. for input ports, tserialio offers no guarantees about the maximum time
  627.      between when a byte arrives at the port and when ttttssssRRRReeeeaaaadddd(3) unblocks.
  628.  
  629.      2. for input and output ports, tserialio offers no guarantees about the
  630.      maximum time between when a byte arrives at the port or is transmitted
  631.      out the port and when ttttssssGGGGeeeettttFFFFiiiilllllllleeeeddddBBBByyyytttteeeessss(3) starts returning a different
  632.      value to reflect that transfer.
  633.  
  634.      3. for input and output ports, tserialio offers no guarantees about the
  635.      maximum time between when a port reaches its fillpoint and when a
  636.      TSport's file descriptor unblocks a sssseeeelllleeeecccctttt(2) or ppppoooollllllll(2).
  637.  
  638.      4. every program that outputs a serial signal has some "operating
  639.      latency" LLLL, such that for any given byte that needs to go out at time TTTT,
  640.      the program will choose to enqueue that byte on the TSport at time TTTT-LLLL or
  641.      later.  Generally (see below) the IRIX scheduler does not guarantee that
  642.      a process will be running at any given time.  Therefore, as LLLL decreases,
  643.      it becomes increasingly likely that your IRIX process will not be running
  644.      in the interval between TTTT-LLLL and TTTT and thus will not be able to enqueue
  645.      the byte for timely transmission.  Tserialio offers no guarantee that any
  646.      particular value of LLLL will always be big enough to avoid this situation.
  647.  
  648.      5. when writing a given (byte, timestamp) pair to an output port using
  649.      ttttssssWWWWrrrriiiitttteeee(3), you must provide tserialio with enough "advance warning" (ie,
  650.      the difference between the current UST at the time of ttttssssWWWWrrrriiiitttteeee(3) and the
  651.      UST timestamp in the pair must be large enough) so that tserialio can
  652.      schedule output of the data with the accuracy described in ttttssssWWWWrrrriiiitttteeee(3).
  653.      This "advance warning" must be added into your "operating latency" as
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))                                                      TTTTSSSSEEEERRRRIIIIAAAALLLLIIIIOOOO((((3333))))
  665.  
  666.  
  667.  
  668.      described above.  Tserialio offers no guarantee that any particular
  669.      amount of "advance warning" will always be enough.
  670.  
  671.      Here are some useful facts about the current implementation (not
  672.      guaranteed to be true of all implementations):
  673.  
  674.      o The latency described in item 2 is at most 2ms.
  675.  
  676.      o The minimum advance warning described in item 5 is 2ms.
  677.  
  678.      o it is possible to reliably perform certain tasks, such as playing a
  679.      MIDI file or controlling a Sony-protocol RS-422 VTR, using the latencies
  680.      practically available to a non-degrading-priority IRIX process (see
  681.      sssscccchhhheeeeddddccccttttllll(2)).  Note that emulating a Sony-protocol RS-422 VTR is not
  682.      necessarily possible.
  683.  
  684.      Real latency guarantees such as those described in items 1, 3, and 4 are
  685.      currently available in multiprocessor configurations using the REACT/Pro
  686.      product.  Such guarantees may be available on all SGI workstations in a
  687.      future IRIX release.  For now, tserialio provides the critical
  688.      functionality for many timely serial applications.
  689.  
  690.  
  691. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  692.      dmGetUST(3dm), serial(7), asoserns(7), termios(7), mdIntro(3dm)
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.